package com.atguigu.tingshu.dispatch.job;

import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.search.client.SearchFeignClient;
import com.atguigu.tingshu.user.client.UserFeignClient;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class DispatchHandler {


    @Autowired
    private SearchFeignClient searchFeignClient;

    /**
     * 更新小时榜热播榜
     */
    @XxlJob("updateLatelyAlbumRanking")
    public void updateLatelyAlbumRanking() {
        Result result = searchFeignClient.updateLatelyAlbumRanking();
        if (!result.getCode().equals(200)) {
            log.error("[定时任务]更新小时榜数据异常：{}", result);
            throw new RuntimeException("更新热播榜失败");
        }
    }

    @Autowired
    private UserFeignClient userFeignClient;


    /**
     * 更新VIP过期用户会员标识
     */
    @XxlJob("updateVipExpireStatus")
    public void updateVipExpireStatus(){
        Result result = userFeignClient.updateVipExpireStatus();
        if (!result.getCode().equals(200)) {
            log.error("[定时任务]更新VIP过期用户会员标识：{}", result);
            throw new RuntimeException("更新VIP过期用户会员标识");
        }
    }


    @XxlJob("hellojob")
    public void hellojob() {
        log.info("hellojob执行.....");
    }

    @XxlJob("shardjob")
    public void shardjob() {
        int shardIndex = XxlJobHelper.getShardIndex();
        int shardTotal = XxlJobHelper.getShardTotal();
        log.info("shardjob.....分片参数，总分片数：{}， 当前分片索引：{}", shardTotal, shardIndex);
    }
}
